<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
	<title>PlaneSpotter</title>

	<meta http-equiv="X-UA-Compatible" content="IE=9" />
	
	<link type="text/css" rel="stylesheet" href="<c:url value="/resources/main.css" />">
	<link type="text/css" rel="stylesheet" href="<c:url value="/resources/cloud-zoom.css" />">
	
	<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
	
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
	<script type="text/javascript" src="<c:url value="/resources/cloud-zoom.1.0.2.js" />"></script>
	
	<script type="text/javascript">
		$(document).ready(function(){
			$(function() {
				$( "#dateTaken" ).datepicker({
					showOn: "button",
					buttonImage: "resources/calendar.gif",
					buttonImageOnly: true,
					dateFormat: "dd/mm/yy",
					changeMonth: true,
					changeYear: true,
				});
			});
			
			$('#lookupButton').click(function(){
				var mark = $("#aircraft\\.mark").val();
				if(mark == '') {
					alert('Please provide aircraft mark');
					return;
				}
				$.post('<c:url value="/aircraft/details"/>', { mark : mark }, function(data) {
					$('#aircraft\\.manufacturer').val(data.manufacturer);
					$('#aircraft\\.model').val(data.model);
					$('#aircraft\\.operatorName').val(data.operatorName);
					$('#aircraft\\.serialNumber').val(data.serialNumber);
				});
			});
		});
	</script>
	
</head>
<body>
		<sec:authorize access="hasAnyRole('ROLE_ADMIN','ROLE_USER')">
			<div class="box">
		        <form:form method="post" enctype="multipart/form-data" modelAttribute="uploadForm">
		        	<table>
						<tr><td>Photo</td><td><input type="file" name="file"/></td></tr>
		            	<tr><td>Date taken</td><td><form:input path="dateTaken" size="8" /></td></tr>
		            	<tr><td>Aircraft Reg. Mark</td><td><form:input path="aircraft.mark" size="8" /><input id="lookupButton" type="button" value="Lookup" class="button">Australian fleet only</td></tr>
		            	<tr><td>Aircraft Manufacturer</td><td><form:input path="aircraft.manufacturer" size="30" /></td></tr>
		            	<tr><td>Aircraft Model</td><td><form:input path="aircraft.model" /></td></tr>
		            	<tr><td>Aircraft Operator</td><td><form:input path="aircraft.operatorName" size="30" /></td></tr>
		            	<tr><td>Aircraft Serial Number</td><td><form:input path="aircraft.serialNumber"/></td></tr>
		            	<tr><td>Airport</td><td><form:input path="airport.iata"/> Please enter IATA code (example: PER for Perth Airport). Lookup functionality is coming soon...</td></tr>
		            	<tr><td valign="top">Comment</td><td><form:textarea cols="30" rows="5" path="comment" /></td></tr>
		            	<tr><td><input type="submit" class="button"/></td></tr>
		            </table>
		        </form:form>
			</div>
		</sec:authorize>
</body>
</html>
